<template>
  <div>
    <h1>三级分类页面</h1>
    <el-tree :data="data" @node-click="nodeclick" :props="defaultProps"> </el-tree>
  </div>
</template>

<script>
import PubSub from 'pubsub-js'
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "name",
      },
    };
  },
  methods: {
    nodeclick(node){
      console.log(node);
      if(node.catLevel==3)
      //事件发布
      PubSub.publish("tree-node",node);
    },
    // 获取数据列表
    getDataList() {
      this.$http({
        url: this.$http.adornUrl("/product/category/tree/list"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        console.log(data);
        this.data = data.list;
      });
    },
  },
  created() {
    this.getDataList();
  },
};
</script>
